/*
 * 时间格式化
 */
export let filterTime = (timestamp, format = 'Y-M-D h:m:s') => {
  if (parseInt(timestamp, 10) === 0 || parseInt(timestamp, 10) === 253402271999 || timestamp === undefined) return '--'
  const date = new Date(timestamp ? (parseInt(timestamp, 10) * 1000) : new Date().getTime())
  let FORMAT = {
    Y: `date.getFullYear()`,
    M: `date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1`,
    D: `date.getDate() < 10 ? '0' + date.getDate() : date.getDate()`,
    h: `date.getHours() < 10 ? '0' + date.getHours() : date.getHours()`,
    m: `date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()`,
    s: `date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()`
  }
  for (const i in FORMAT) {
    if (format.indexOf(i) !== -1) {
      format = format.replace(i, eval(FORMAT[i]))
    }
  }
  return format
}

export let ymdtime = (timestamp) => {
  return filterTime(timestamp, 'Y-M-D')
}

/*
 * 截断hash
 */
export let filterHash = (str, num) => {
  let length = num || 12
  return String(str).substr(0, length) + '...' + String(str).substr(-4);
}

export let filterStatus = (status) => {
  switch (status) {
    case '':
      return '全部';
    case 0:
      return '待确认';
    case 1:
      return '确认发行'
    case 2:
      return '撤销发行'
    case 3:
      return '撤销成功'
    case 4:
      return '撤销失败'
    case 5:
      return '待审核'
    case 6:
      return '允许发行(人工)'
    case 7:
      return '拒绝发行(人工)'
    case 8:
      return '发行成功'
    case 9:
      return '发行失败'
    default:
      break;
  }
}

// 数字位数过滤
export let filterNum = (num) => {
  if (!num || num === null || num === '') return
  let n = String(num).split('.')
  let b = parseInt(n[0]).toString();
  let len = b.length;
  let result = ''
  if (len <= 3) {
    result = b;
  } else {
    let r = len % 3;
    result = r > 0 ? b.slice(0, r) + "," + b.slice(r, len).match(/\d{3}/g).join(",") : b.slice(r, len).match(/\d{3}/g).join(",");
  }
  if (n[1]) {
    return result + `.${n[1]}`
  } else {
    return result
  }
}

// 探索应用样式
export let explorerStyle = (num) => {
  switch (Number(num)) {
    case 1:
      return '竖列排列'
    case 2:
      return '宫格排列'
    case 3:
      return '滑动排列'
    case 4:
      return '专题模式'
    default:
      break;
  }
}

// 认证状态
export let auditStatus = (num) => {
  switch (Number(num)) {
    case 1:
      return '已通过'
    case 2:
      return '待审核'
    case -2:
      return '已拒绝'
    default:
      break;
  }
}

// 提币自动审核分类
export let widthdrawCategory = (num) => {
  switch (Number(num)) {
    case 1:
      return '数量'
    case 2:
      return '价值'
    default:
      break;
  }
}

//快讯置顶
export let newsTop = (num) => {
  switch (Number(num)) {
    case 0:
      return '非置顶'
    case 1:
      return '置顶'
    default:
      break;
  }
}

//快讯高亮
export let newsHightlight = (num) => {
  switch (Number(num)) {
    case 0:
      return '正常'
    case 1:
      return '高亮'
    default:
      break;
  }
}

//快讯状态
export let newsStatus = (num) => {
  switch (Number(num)) {
    case 0:
      return '未发布'
    case 1:
      return '发布'
    case 2:
      return '失效'
    default:
      break;
  }
}


export default {
  filterTime,
  ymdtime,
  filterHash,
  filterStatus,
  filterNum,
  explorerStyle,
  auditStatus,
  widthdrawCategory,
  newsTop,
  newsHightlight,
  newsStatus,
}